package com.tiancheng.onecode.controller.commom;

import com.tiancheng.onecode.configuration.ExampleImageProperties;
import com.tiancheng.onecode.model.response.Result;
import com.tiancheng.onecode.service.IMerchantService;
import com.tiancheng.onecode.trade.model.request.MerchantBranchBankListReqVO;
import com.tiancheng.onecode.trade.model.response.MerchantBranchBankListResVO;
import com.tiancheng.onecode.trade.model.response.QueryAreaRes;
import com.tiancheng.onecode.trade.model.response.QueryMccRes;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;
import java.util.List;

/**
 * @ClassName MemberOrderApiController
 * @Description 客户订单-客户端接口
 * @Author kellen
 * @Date 2025/1/14 20:43
 */
@Slf4j
@RequestMapping("/common")
@RestController
public class CommonController {

    @Resource
    private IMerchantService merchantService;
    @Resource
    private ExampleImageProperties exampleImageProperties;

    /**
     * 获取最新省市区以及行业数据列表
     * @param dataType 文件类型 province,city,county,mcc可选，分别对应省、市、区和行业数据。
     * @return
     * @throws IOException
     */
    @GetMapping("/regionData")
    public Result<String> upload(@RequestParam("dataType") String dataType) throws IOException {
        //把文件的内容存储到本地磁盘上
        final String url = merchantService.regionData(dataType);
        return Result.success(url);
    }

    /**
     * 查询地区信息
     * @param parentAreaCode
     * @return
     */
    @GetMapping("/getRegion")
    public Result<List<QueryAreaRes>> queryByParentAreaCode(@RequestParam(name = "parentAreaCode",required = false) String parentAreaCode) {
        return Result.success(merchantService.queryByParentAreaCode(parentAreaCode));
    }

    /**
     * 查询行业信息
     * @param mccName
     * @return
     */
    @GetMapping("/mccList")
    public Result<List<QueryMccRes>> mccList(@RequestParam(name = "mccName",required = false) String mccName) {
        return Result.success(merchantService.mccList(mccName));
    }

    /**
     * 所属支行查询接口
     *
     * @return
     * @throws IOException
     */
    @PostMapping("/branchBankList")
    public Result<List<MerchantBranchBankListResVO>> branchBankList(@RequestBody @Validated MerchantBranchBankListReqVO merchantBranchBankListReqVO) throws IOException {
        //把文件的内容存储到本地磁盘上
        final List<MerchantBranchBankListResVO> merchantPayRegResVOs = merchantService.branchBankList(merchantBranchBankListReqVO);
        return Result.success(merchantPayRegResVOs);
    }

    /**
     * 查询示例图片
     * @return
     */
    @GetMapping("/exampleImage")
    public Result<List<ExampleImageProperties.ImageItem>> exampleImage() {
        return Result.success(exampleImageProperties.getList());
    }


}
